Skip to content

Add try_clone for TcpStream #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Add try_clone for TcpStream #642

wants to merge 1 commit into from

Conversation

atbentley
Copy link

From the discussion in #553

I also updated the client/server example to use try_clone instead of Arc, as well as added a small test.

@atbentley
Copy link
Author

Not sure why this is failing on windows, is anyone able to point me in a direction here?

@yoshuawuyts
Copy link
Contributor

@atbentley I'm unsure, but it seems this might be an issue in mio:

---- cloned_streams stdout ----
thread 'cloned_streams' panicked at 'cannot register an I/O event source: Os { code: 87, kind: Other, message: "The parameter is incorrect." }', src\libcore\result.rs:1188:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

We're not passing any extra parameters to the underlying OS primitives here; so it feels like it's coming from a lower level. This makes me wonder if going down the Arc route isn't the more reliable option.

@ghost
Copy link

ghost commented Jan 13, 2020

This could be a problem related to tokio-rs/tokio#774

@jdafont
Copy link

jdafont commented Jan 22, 2020

Definitely looking forward to this. As it stands, I don’t see any way to read a socket on one thread and write it on another on rust stable. I’ve worked around it in the meantime using Arc::get_mut_unchecked, which feels pretty gross. It does seem to work fine, though.

@jdafont
Copy link

jdafont commented Jan 24, 2020

I attempted creating a std TcpStream, cloning it, and then using async_std::net::TcpStream's From<> impl to convert the std stream. I also received the error

thread 'main' panicked at 'cannot register an I/O event source: Os { code: 87, kind: Other, message: "The parameter is incorrect." }', C:\Users\jfont\.cargo\registry\src\github.1485827954.workers.dev-1ecc6299db9ec823\async-std-1.4.0\src\net\driver\mod.rs:183:20

This happens after I've already converted the first one and I'm converting the second one. Here's the demonstration code:

let tcp_a = std::net::TcpStream::connect("127.0.0.1:43800")?;
let tcp_b = tcp_a.try_clone()?;
let reader = Arc::new(Mutex::new(async_std::net::TcpStream::from(tcp_a)));
let writer = Arc::new(Mutex::new(async_std::net::TcpStream::from(tcp_b)));

Here's the section relevant to the panic

pub fn new(source: T) -> Watcher<T> {
Watcher {
entry: REACTOR
.register(&source)
.expect("cannot register an I/O event source"),
source: Some(source),
}
}

@ghost ghost mentioned this pull request Jan 28, 2020
@atbentley atbentley closed this by deleting the head repository Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants